<h1>Report Jaringan</h1>
<?php
$this->renderPartial('application.modules.member.views.main.info');
?>
<br /><br />
<h2>Total Jaringan</h2>
<div class="list">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th rowspan="2" width="60">Sponsor</th>
            <th colspan="2">Titik</th>
            <th rowspan="2" width="60">Pasangan</th>
            <th rowspan="2" width="60">Flushout</th>
            <th colspan="2">Menunggu Dipasangkan</th>
        </tr>
        <tr>
            <th width="50">Kiri</th>
            <th width="50">Kanan</th>
            <th width="50">Kiri</th>
            <th width="50">Kanan</th>
        </tr>
        <tr>
            <td align="center"><?php echo $summary['total_sponsor']; ?></td>
            <td align="center"><?php echo $summary['total_node_left']; ?></td>
            <td align="center"><?php echo $summary['total_node_right']; ?></td>
            <td align="center"><?php echo $summary['total_match']; ?></td>
            <td align="center"><?php echo $summary['total_flushout']; ?></td>
            <td align="center"><?php echo $summary['wait_left']; ?></td>
            <td align="center"><?php echo $summary['wait_right']; ?></td>
        </tr>
    </table>
</div>
<br /><br />
<h2>History Perkembangan Jaringan</h2>
<div class="add">
    <form action="" method="post" name="member_form">
        <table cellpadding="0" cellspacing="0">
            <tr class="title">
                <th colspan="5" style="text-align:left;"><strong>&nbsp;</strong></th>
            </tr>
            <tr>
                <th width="80">Lihat data</th>
                <td width="100" class="no-border">
                    <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'name' => 'date_start',
                        'value' => $date_start,
                        'options' => array(
                            'showAnim' => 'fold',
                            'dateFormat' => 'yy-mm-dd', // save to db format
                            'altField' => '#self_pointing_id',
                            'altFormat' => 'yy-mm-dd', // show to user format
                            'changeYear' => true,
                        ),
                        'htmlOptions' => array(
                            'style' => 'padding:3px 4px;',
                            'size' => 10,
                        ),
                    ));
                    ?>
                </td>
                <td width="10" class="no-border">s.d.</td>
                <td width="100" class="no-border">
                    <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'name' => 'date_end',
                        'value' => $date_end,
                        'options' => array(
                            'maxDate' => '+0', //('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +1w')
                            'showAnim' => 'fold',
                            'dateFormat' => 'yy-mm-dd', // save to db format
                            'altField' => '#self_pointing_id',
                            'altFormat' => 'yy-mm-dd', // show to user format
                            'changeYear' => true,
                        ),
                        'htmlOptions' => array(
                            'style' => 'padding:3px 4px;',
                            'size' => 10,
                        ),
                    ));
                    ?>
                </td>
                <td class="no-border"><input type="submit" name="search" class="button" value="Tampilkan" /></td>
            </tr>
        </table>
    </form>
</div>
<br />
<div class="list">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th rowspan="3">Tanggal</th>
            <th rowspan="3">Sponsor</th>
            <th colspan="4">Titik</th>
            <th rowspan="2" colspan="2">Akumulasi<br />Titik<br />Harian</th>
            <th rowspan="3">Pasangan</th>
            <th rowspan="3">Status</th>
        </tr>
        <tr>
            <th colspan="2">Pertumbuhan</th>
            <th colspan="2">Menunggu Sebelumnya</th>
        </tr>
        <tr>
            <th>Kiri</th>
            <th>Kanan</th>
            <th>Kiri</th>
            <th>Kanan</th>
            <th>Kiri</th>
            <th>Kanan</th>
        </tr>
        <?php
        if ($data != false) {
            $total_sponsor = $total_node_left = $total_node_right = $total_match = $total_match_real = $total_flushout = 0;
            foreach ($data as $row) {
                $prev_wait_left = vo_network::get_wait_node_bonus($row['netgrow_bonus_network_id'], 'left', $row['netgrow_bonus_date']);
                $prev_wait_right = vo_network::get_wait_node_bonus($row['netgrow_bonus_network_id'], 'right', $row['netgrow_bonus_date']);
                $node_left = $row['netgrow_bonus_node_left'] + $prev_wait_left;
                $node_right = $row['netgrow_bonus_node_right'] + $prev_wait_right;
                $match_real = ($node_left > $node_right) ? $node_right : $node_left;
                $flushout = ($match_real >= 12) ? 'Flush' : '-';

                $total_sponsor += $row['netgrow_bonus_sponsor'];
                $total_node_left += $row['netgrow_bonus_node_left'];
                $total_node_right += $row['netgrow_bonus_node_right'];
                $total_match += $row['netgrow_bonus_match'];
                $total_match_real += $match_real;
                //$total_flushout += $flushout;

                echo '<tr>';
                echo '<td align="center">' . $row['netgrow_bonus_date'] . '</td>';
                echo '<td align="center">' . $row['netgrow_bonus_sponsor'] . '</td>';
                echo '<td align="center">' . $row['netgrow_bonus_node_left'] . '</td>';
                echo '<td align="center">' . $row['netgrow_bonus_node_right'] . '</td>';
                echo '<td align="center">' . $prev_wait_left . '</td>';
                echo '<td align="center">' . $prev_wait_right . '</td>';
                echo '<td align="center">' . $node_left . '</td>';
                echo '<td align="center">' . $node_right . '</td>';
                echo '<td align="center">' . $match_real . '</td>';
                echo '<td align="center">' . $flushout . '</td>';
                echo '</tr>';
            }
            echo '<tr class="title">';
            echo '<td align="center"><strong>TOTAL</strong></td>';
            echo '<td align="center"><strong>' . $total_sponsor . '</strong></td>';
            echo '<td align="center"><strong>' . $total_node_left . '</strong></td>';
            echo '<td align="center"><strong>' . $total_node_right . '</strong></td>';
            echo '<td align="center"><strong>-</strong></td>';
            echo '<td align="center"><strong>-</strong></td>';
            echo '<td align="center"><strong>-</strong></td>';
            echo '<td align="center"><strong>-</strong></td>';
            echo '<td align="center"><strong>' . $total_match_real . '</strong></td>';
            echo '<td align="center"><strong>-</strong></td>';
            echo '</tr>';
        } else {
            echo '<tr><td colspan="10" align="center">-----====-----</td></tr>';
        }
        ?>
    </table>
</div>